package com.nwpu.coursesupport.controller;

import com.nwpu.coursesupport.entity.CourseTarget;
import com.nwpu.coursesupport.entity.EvaluationOfCourseTargetEntity;
import com.nwpu.coursesupport.entity.bean.Response;
import com.nwpu.coursesupport.entity.params.CourseTargetSubmitParam;
import com.nwpu.coursesupport.service.imple.CourseTargetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping
@RestController
public class CourseTargetController {
    @Autowired
    private CourseTargetService courseTargetService;

    @RequestMapping("/courseTargets")
    public Response courseTargets() {
        return courseTargetService.findAll();
    }

    @RequestMapping("courseTargets/{courseId}")
    public Response courseTargetsByCourseId(@PathVariable("courseId") Integer courseId) {
//        System.out.println("courseId:::" + courseId);
//        System.out.println("testtttt:" );
        List<CourseTarget> courseTargets = courseTargetService.courseTargetsByCourseId(courseId);
//        System.out.println("testtttt:" +courseTargets);
        return Response.ok(courseTargets);
//        return courseTargets;
    }

    @RequestMapping("courseTargets/ajaxSubmit")
    public Response ajaxSubmit(@RequestBody CourseTargetSubmitParam data) {
        System.out.println("data......." + data);
        Integer courseId = data.getCourseId();
        List<CourseTarget> courseTargets = data.getCourseTargets();
        List<EvaluationOfCourseTargetEntity> evaluationOfCourseTargets = data.getEvaluationOfCourseTargets();
        return courseTargetService.submitCourseTarget(courseId, courseTargets, evaluationOfCourseTargets);
    }


}
